#!/opt/php/bin/php
<?php
require_once 'TVB/ImageInfrastructure/Client/requires.php';

$ii_client = new ImageInfrastructureClient();

//////////////////////////////////////
/// GetExportImageUrlTroublesomely ///
//////////////////////////////////////
/*
source_id: 269
export_id: 282
export_id: 282
*/
$source_id = 10000;
$width = 100;
$height = 100;
$resize_mode = 2;
$watermark = '';
$format = 2;
$export_arg = 85;
$ret = $ii_client->getExportImageUrlTroublesomely($source_id, $width, $height, $resize_mode, $watermark, $format, $export_arg);
var_dump($ret);
//exit;

///////////////////////////////
/// GetExportImageUrlEasily ///
///////////////////////////////
$export_id = 282;
$ret = $ii_client->getExportImageUrlEasily($export_id);
var_dump($ret);
//exit;

$export_id = 283;
$destination_id = 1;
echo $ii_client->queryStatusEasily($export_id, $destination_id) . "\n" ;


//////////////////////////////
//// GetSourceImageUrl ///////
//////////////////////////////
$source_id = 269;
$ret = $ii_client->getSourceImageUrl($source_id);
var_dump($ret);
//exit;

$destination_id = '1';
$login_id = 'qoo';
$width = 100;
$height = 100;
$resize_mode = 2;
$watermark = '';
$format = '2';
$export_arg = '85';
//$callback_url = 'http://ii.api.tvb.com/callback.php';
$callback_url = '';

#$tmp = $ii_client->upload($login_id, 'file/test.jpg');
$tmp = $ii_client->upload($login_id, 'file/notok.jpg');
var_dump($tmp);

$source_id = $tmp->source_id;
echo "source_id: $source_id\n";

$export_id = $ii_client->requestExport($login_id, $source_id, $width, $height, $resize_mode, $watermark, $format, $export_arg, '');
echo "export_id: $export_id\n";

$export_id = $ii_client->requestDistribute($login_id, $source_id, $width, $height, $resize_mode, $watermark, $format, $export_arg, $destination_id, $callback_url);
echo "export_id: $export_id\n";

echo $ii_client->queryStatusEasily($export_id, $destination_id) . "\n" ;

sleep(1);

echo $ii_client->queryStatusEasily($export_id, $destination_id) . "\n" ;

sleep(1);

echo $ii_client->queryStatusEasily($export_id, $destination_id) . "\n" ;

sleep(1);

echo $ii_client->queryStatusEasily($export_id, $destination_id) . "\n" ;

sleep(1);

echo $ii_client->queryStatusEasily($export_id, $destination_id) . "\n" ;
?>
